<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/13
 * Time: 14:03
 */
namespace app\blog\controller;
use app\blog\model\AgratioModel;
use cmf\controller\AdminBaseController;

class AgencyController extends AdminBaseController
{
    public function _initialize(){
        parent::_initialize(); //监听是否登录
    }
    /**
     * 代理商等级页面
     */
    public function index(){
        //获取代理等级信息
        $a         = new AgratioModel();
        $result    = $a->index();
        $this->assign('result',$result);
        $this->assign('page',$result->render());
        return $this->fetch();
    }
    /**
     * 等级添加页面
     */
    public function add(){
        return $this->fetch();
    }
    /**
     * 等级添加
     */
    public function addPost(){
        $date           = $this->request->param();
        $result         = $this->validate($date, 'Agency');
        if ($result !== true) {
            $this->error($result);
        }
        $a = new AgratioModel();
        $rest = $a->addPost($date);
        if($rest != false){
            $this->success('操作成功','Agency/index');
        }else{
            $this->error('操作失败');
        }
    }
    /**
     * 等级修改页面
     * $id  id
     */
    public function change(){
        //根据id获取指定记录
        $id            = $this->request->param('id');
        $a             = new AgratioModel();
        $result        = $a->getOne($id);
        $this->assign('result',$result);
        return $this->fetch();
    }
    /**
     * 等级修改
     * $date 参数
     */
    public function changePost(){
        $date                = $this->request->param();
        $id                  = $date['id'];
        $data                = array();
        $data['agr_level']   = $date['agr_level'];
        $data['money']       = $date['money'];
        $data['number']      = $date['number'];
        if($data['agr_level'] == '' || $data['money'] == '' || $data['number'] == ''){
            $this->success('不能我为空');
        }
        $a                   = new AgratioModel();
        $result              = $a->change($id,$data);
        if($result != false){
            $this->success('操作成功','Agency/index');
        }else{
            $this->error('操作失败');
        }
    }
    /**
     * 等级删除
     */
    public function del(){
        $date       = $this->request->param('id');
        $a          = new AgratioModel();
        $result     = $a->del($date);
        if($result != false){
            $this->success('操作成功','Agency/index');
        }else{
            $this->error('操作失败','Agency/index');
        }
    }



}